package com.dati.servlet;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import util.AllTypeList;
import util.Constant;
import util.UtilDAO;

import com.UserModule.bean.TbUserBean;
import com.dati.bean.Answer;
import com.dati.bean.DatiMiddle;
import com.dati.bean.DatiType;
import com.dati.bean.Xulie;
import com.dati.bean.setTime;
import com.dati.dao.DatiDao;
import com.dati.dao.DatiTypeDao;
import com.dianbo.bean.DianboType;
import com.jifen.bean.JiFen;
import com.jifen.dao.JifenDao;
import com.jspsmart.upload.SmartUpload;

public class DatiServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public DatiServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String method= request.getParameter("method");
		TbUserBean user = (TbUserBean)request.getSession().getAttribute("User");
		if(method.equals("setSubmit")){//答题设置积分
			String num = request.getParameter("num");
			String xilieId = request.getParameter("xilieId");
		
			JiFen jiFen = new JiFen();
			jiFen.setTypeId("");
			jiFen.setIntegralType(0);
			jiFen.setIntegralValue(num);
			jiFen.setSeriseId(xilieId);
			jiFen.setSetTime(Constant.decodeDate());
			jiFen.setUserId(user.getUserId());
			boolean bo = new JifenDao().addJiFenXilie(jiFen);
			if(bo){
				request.getSession().setAttribute("result", "积分设置成功");
			}else {
				request.getSession().setAttribute("result", "积分设置失败");
			}
			List list = new AllTypeList().getLastValue(user.getUserId());
			List<DianboType> dianboTypeList = (ArrayList<DianboType>)list.get(0);
			StringBuffer sb = (StringBuffer)list.get(1);
		   
		    request.getSession().setAttribute("dianboTypeList", dianboTypeList);
		    request.getSession().setAttribute("sb", sb);
		    response.sendRedirect("jifen/jiFenupLoadList.jsp");
		}else if(method.equals("setDown")){//答题下行积分设置显示
			String dianboId = request.getParameter("dianboId");
			String condition=" answerTypeId = '"+dianboId+"'";
			List<DatiType> datiTypeList = new DatiTypeDao().getAllDaTiType("tb_answer_type","createTime",condition);
			request.getSession().setAttribute("datiTypeList", datiTypeList);
			response.sendRedirect("jifen/jiFendownDatiSet.jsp");
		}else if(method.equals("setDownSubmit")){//答题下行积分设置提交
			String num = request.getParameter("num");
			String typeId = request.getParameter("typeId");
		
			JiFen jiFen = new JiFen();
			jiFen.setTypeId(typeId);
			jiFen.setIntegralType(1);
			jiFen.setIntegralValue(num);
			jiFen.setSeriseId("");
			jiFen.setSetTime(Constant.decodeDate());
			jiFen.setUserId(user.getUserId());
			boolean bo = new JifenDao().addJiFen(jiFen);
			if(bo){
				request.getSession().setAttribute("result", "点播下行积分设置成功");
			}else {
				request.getSession().setAttribute("result", "点播下行积分设置失败");
			}
			
			List list = new AllTypeList().getDownValue(user.getUserId());
			List<DianboType> dianboTypeList = (ArrayList<DianboType>)list.get(0);
			List<DatiType> datiTypeList = (ArrayList<DatiType>)list.get(1);
		    request.getSession().setAttribute("result", "");
		    request.getSession().setAttribute("dianboTypeList", dianboTypeList);
		    request.getSession().setAttribute("datiTypeList", datiTypeList);
		    response.sendRedirect("jifen/jiFendownList.jsp");
		}else if("lookdati".equals(method)){//答题库管理
			 String datiType = request.getParameter("datiType");
			 String content = request.getParameter("content");
			 List<Object> list = this.getLst(datiType, content,user.getUserId());
			 List<DatiType> datiTypeList =(List<DatiType>)list.get(0);
			 List<Answer> datiList = (List<Answer>)list.get(1);
			 
			 request.getSession().setAttribute("datiList", datiList);
			 request.getSession().setAttribute("datiTypeList", datiTypeList);
			 request.getSession().setAttribute("result", "");
			 request.getSession().setAttribute("datiSelected", "0");
			 request.getSession().setAttribute("content",content);
			 response.sendRedirect("hudong/datiList.jsp");
			
		}else if("looksearch".equals(method)){//查询答题
			String datitype= Constant.decodeString(request.getParameter("datitype"));
			String content = Constant.decodeString(request.getParameter("content"));
			String condition="1=1";
			List<Answer> answerList = new ArrayList<Answer>();
			if(datitype.equals("0")){
			}else{
				condition+=" and answerTypeId='"+datitype+"'";
			}
			
			List<Xulie> xulieList = new DatiTypeDao().getXulieByTypeId("tb_serise", "", condition);//得到系列
			String xulieId="";
			if(xulieList!=null&&xulieList.size()>0){
				for(Xulie xulie:xulieList){
					if(xulieId.equals("")){
						xulieId+=xulie.getSeriseId();
					}else{
						xulieId+=","+xulie.getSeriseId();
					}
				}
				String conditionMidd="seriseId in("+xulieId+")";
				if(!content.equals("")){
					conditionMidd+=" and answerContent like '%"+content+"%'";
				}
				
				List<DatiMiddle> datiMiddleList = new DatiDao().getDatiMiddle("tb_answer_middle", "", conditionMidd);//得到中间表记录
				String answerMiddle="";
				if(datiMiddleList!=null&&datiMiddleList.size()>0){
					for(DatiMiddle datiMiddle:datiMiddleList){
						if(answerMiddle.equals("")){
							answerMiddle+=datiMiddle.getAnswerMiddleId();
						}else{
							answerMiddle+=","+datiMiddle.getAnswerMiddleId();
						}
					}
					String conditionAnswer="answerMiddleId in("+answerMiddle+")";//取答题表中的记录
					answerList = new DatiDao().getAnswerList("tb_answer", "", conditionAnswer);
				}
			}
			
			
			String datiTypeCondition=" userId="+user.getUserId();
			List<DatiType> datiTypeList = new DatiTypeDao().getAllDaTiType("tb_answer_type", "", datiTypeCondition);
			
			 request.getSession().setAttribute("datiList", answerList);
			 request.getSession().setAttribute("datiTypeList", datiTypeList);
			 request.getSession().setAttribute("result", "");
			 request.getSession().setAttribute("datiSelected", datitype);
			 request.getSession().setAttribute("content",content);
			 response.sendRedirect("hudong/datiList.jsp");
		}else if("addDati".equals(method)){
			String datiType = request.getParameter("datiType");
			String xilieType = request.getParameter("xilieType");
			String datianswer = Constant.decodeString(request.getParameter("datianswer"));
			String daticontent = Constant.decodeString(request.getParameter("daticontent"));
			DatiMiddle datiMiddle = new DatiMiddle();
			String middleId = Constant.getNumT();
			datiMiddle.setAnswerMiddleId(middleId);
			datiMiddle.setAnswerContent(daticontent);
			datiMiddle.setCreateTime(Constant.decodeDate());
			datiMiddle.setRightAnswer(datianswer);
			datiMiddle.setSeriseId(xilieType);
			boolean bo = new DatiDao().saveDatiMiddle(datiMiddle);
			if(bo){
				Answer answer = new Answer();
				answer.setAnswerIntegral("");
				answer.setAnswerMiddleId(middleId);
				answer.setAnswerUpPhone("");
				answer.setAnswerUpTime(Constant.decodeDate());
				answer.setReceiveId(0);
				boolean boo =new DatiDao().saveAnswer(answer);
				if(boo){
					request.getSession().setAttribute("result", "添加答题成功!");
				}
			}
			List list = this.getLst("", "",user.getUserId());
			
			 List<DatiType> datiTypeList =(ArrayList<DatiType>)list.get(0);
			 List<Answer> datiList = (ArrayList<Answer>)list.get(1);
			 
			 request.getSession().setAttribute("datiList", datiList);
			 request.getSession().setAttribute("datiTypeList", datiTypeList);
			 request.getSession().setAttribute("datiSelected", "0");
			 request.getSession().setAttribute("content","");
			 response.sendRedirect("hudong/datiList.jsp");
		}else if("deleteOneDati".equals(method)){
			String datiId =request.getParameter("datiId");
			String content = Constant.decodeString(request.getParameter("content"));
			String datiSelected = request.getParameter("datiSelected");
			boolean bo = UtilDAO.del("tb_answer", "answerId", Integer.parseInt(datiId));
			if(bo){
				request.getSession().setAttribute("result", "答题删除成功!");
			}else{
				request.getSession().setAttribute("result", "答题删除失败!");
			}
			List<Object> list = this.getLst(datiSelected, content, user.getUserId());
			
			 List<DatiType> datiTypeList =(ArrayList<DatiType>)list.get(0);
			 List<Answer> datiList = (ArrayList<Answer>)list.get(1);
			 
			 request.getSession().setAttribute("datiList", datiList);
			 request.getSession().setAttribute("datiTypeList", datiTypeList);
			 request.getSession().setAttribute("datiSelected", datiSelected);
			 request.getSession().setAttribute("content",content);
			 response.sendRedirect("hudong/datiList.jsp");
		}else if("deleteAll".equals(method)){
			String idList = request.getParameter("idList");
			idList = idList.substring(0, idList.length()-1);
			String content = Constant.decodeString(request.getParameter("content"));
			String datiSelected = request.getParameter("datiSelected");
			String condition=" tb_answer where answerId in("+idList+")";
			boolean result=UtilDAO.delAll(condition);
			if(result){
				request.getSession().setAttribute("result", "答题记录删除成功！");
			}else{
				request.getSession().setAttribute("result", "答题记录删除失败！");
			}
			
			List<Object> list = this.getLst(datiSelected, content, user.getUserId());
			
			 List<DatiType> datiTypeList =(ArrayList<DatiType>)list.get(0);
			 List<Answer> datiList = (ArrayList<Answer>)list.get(1);
			 
			 request.getSession().setAttribute("datiList", datiList);
			 request.getSession().setAttribute("datiTypeList", datiTypeList);
			 request.getSession().setAttribute("datiSelected", datiSelected);
			 request.getSession().setAttribute("content",content);
			 response.sendRedirect("hudong/datiList.jsp");
		}else if("importDati".equals(method)){

			String realImagePath = Constant.decodeString(request
					.getParameter("realImagePath"));
			String tempPath = request.getRealPath("/")
					+ "upload".replace("\\", "/");
			String result = "";
			File file = new File(tempPath);
			if(!file.isFile()){
				file.mkdirs();
			}
			// new a SmartUpload object
			SmartUpload su = new SmartUpload();
			su.setCharset("UTF-8");// 使用时候最关键的一步
			// 上传初始化
			su.initialize(this.getServletConfig(),request,response);

			// 设定上传限制
			// 1.限制每个上传文件的最大长度。
			su.setMaxFileSize(10000000);
			// 2.限制总上传数据的长度。
			su.setTotalMaxFileSize(20000000);
			// 3.设定允许上传的文件（通过扩展名限制）,仅允许doc,txt文件。
			su.setAllowedFilesList("xls,XLS");
			boolean sign = true;
			// 4.设定禁止上传的文件（通过扩展名限制）,禁止上传带有exe,bat,jsp,htm,html扩展名的文件和没有扩展名的文件。
			try {
				su.setDeniedFilesList("exe,bat,jsp,htm,html");
				// 上传文件
				su.upload();
				// 将上传文件保存到指定目录
				tempPath = tempPath.replace("\\", "/");
				tempPath = tempPath + "/";
				
				su.save(tempPath);
				System.out.println("文件名称"+su.getFiles().getFile(0).getFileName());
				tempPath += "\\" + su.getFiles().getFile(0).getFileName();
				tempPath = tempPath.replace("\\", "/");
				tempPath = tempPath.replace("//", "/");
				System.out.println("tempsssssssssssssPath==="+tempPath);
				
				
				Workbook wb;
				InputStream is2 = new FileInputStream(tempPath);
				wb = Workbook.getWorkbook(is2);
				Sheet sheet = wb.getSheet(0);
				int row = sheet.getRows();
				List<Answer> answerList = new ArrayList<Answer>();
				String condition="userId="+user.getUserId();
				List<DatiType> datiTypeList = new DatiTypeDao().getAllDaTiType("tb_answer_type", "", condition);//得到数据库中已存在答题类型
				List<String> datiTypeNameList = new ArrayList<String>();//得到已经存在库中的答题类型的名称
				Hashtable<String,List<String>> ht = new Hashtable<String,List<String>>();//得到答题类型下的系列     以答题名称/系列LIST
				
				List<String> saveTypeName = new ArrayList<String>();//要保存的答题类型名称
				List<String> xilieName = new ArrayList<String>();//要保存的系列名称
				
				
				List<Xulie> xilieList = new ArrayList<Xulie>();
				
				if(datiTypeList!=null&&datiTypeList.size()>0){
					for(DatiType datiType:datiTypeList){
						datiTypeNameList.add(datiType.getTypeName());
						String conditionXulie = "answerTypeId='"+datiType.getAnswerTypeId()+"'";
						List<String> xilieNameList = new ArrayList<String>();
						xilieList = new DatiTypeDao().getXulieByTypeId("tb_serise", "", conditionXulie);
						if(xilieList!=null&&xilieList.size()>0){
							xilieNameList = new DatiTypeDao().getXilieNameList(xilieList);
						}
						ht.put(datiType.getTypeName(), xilieNameList);
					}
				}
				List<DatiMiddle> datiMiddleList = new ArrayList<DatiMiddle>();//要保存的中间表内容
				List<Xulie> xlList = new ArrayList<Xulie>();//要保存的系列
				List<Answer> answerLst = new ArrayList<Answer>();//要保存的答题
				List<DatiType> dtTypeLst = new ArrayList<DatiType>();//要保存的答题类型
				Hashtable<String,String> hhtType = new Hashtable<String,String>();
				Hashtable<String,String> hhtSerise = new Hashtable<String,String>();
				//模式:类型|||||系列|||题目||||答案
				for(int i =1;i<row;i++){
					Cell firstCell = sheet.getCell(0, i);
					String firstContent = firstCell.getContents().trim();
					Cell secondCell = sheet.getCell(1, i);
					String secondContent = secondCell.getContents().trim();
					Cell threeCell = sheet.getCell(2, i);
					String threeContent = threeCell.getContents().trim();
					Cell fourCell = sheet.getCell(3, i);
					String fourContent = fourCell.getContents().trim();
					/*if(firstContent.equals("")&&threeContent.equals("")&&fourContent.equals("")){
						continue;
					}*/
					if(datiTypeNameList.contains(firstContent)){//数据库中存在此答题类型
						List<String> xn = ht.get(firstContent);
						String answerTypeCodition=" userId="+user.getUserId()+" and typeName='"+firstContent+"'";
						List<DatiType> datiTypeLst = new DatiTypeDao().getAllDaTiType("tb_answer_type", "", answerTypeCodition);
						if(xn.contains(secondContent)){//数据库中已存在此系列
							String xilieTypeCondition=" answerTypeId='"+datiTypeLst.get(0).getAnswerTypeId()+"' and seriseName ='"+secondContent+"'";
							List<Xulie> xilieType = new DatiTypeDao().getXulieByTypeId("tb_serise","", xilieTypeCondition);
							DatiMiddle  datiM = new DatiMiddle();
							String datiMId=Constant.getNumT();
							datiM.setAnswerContent(threeContent);
							datiM.setAnswerMiddleId(datiMId);
							datiM.setCreateTime(Constant.decodeDate());
							datiM.setRightAnswer(fourContent);
							datiM.setSeriseId(xilieType.get(0).getSeriseId());
							datiMiddleList.add(datiM);
							
							Answer answer = new Answer();
							answer.setAnswerIntegral("");
							answer.setAnswerMiddleId(datiMId);
							answer.setAnswerUpPhone("");
							answer.setAnswerUpTime(Constant.decodeDate());
							answer.setReceiveId(0);
							answerLst.add(answer);
						}else {//数据库中不存在此系列
							System.out.println("不存在系列"+secondContent);
							Xulie xil = new Xulie();
							String xilId = Constant.getNum();
							xil.setAnswerTypeId(datiTypeLst.get(0).getAnswerTypeId());
							xil.setCreateTime(Constant.decodeDate());
							xil.setSeriseId(xilId);
							xil.setSeriseName(secondContent);
							xlList.add(xil);
							
							DatiMiddle  datiM = new DatiMiddle();
							String datiMId = Constant.getNumT();
							datiM.setAnswerContent(threeContent);
							datiM.setAnswerMiddleId(datiMId);
							datiM.setCreateTime(Constant.decodeDate());
							datiM.setRightAnswer(fourContent);
							datiM.setSeriseId(xilId);
							datiMiddleList.add(datiM);
							
							Answer answer = new Answer();
							answer.setAnswerIntegral("");
							answer.setAnswerMiddleId(datiMId);
							answer.setAnswerUpPhone("");
							answer.setAnswerUpTime(Constant.decodeDate());
							answer.setReceiveId(0);
							answerLst.add(answer);
						}
					}else if(saveTypeName.contains(firstContent)){
						System.out.println("firstContent=="+firstContent);
						String Typeid = hhtType.get(firstContent);
						System.out.println("type_id="+Typeid);
						if(xilieName.contains(secondContent)){
							String seriseId = hhtSerise.get(secondContent);
							DatiMiddle  datiM = new DatiMiddle();
							String datiMId = Constant.getNumT();
							datiM.setAnswerContent(threeContent);
							datiM.setAnswerMiddleId(datiMId);
							datiM.setCreateTime(Constant.decodeDate());
							datiM.setRightAnswer(fourContent);
							datiM.setSeriseId(seriseId);
							datiMiddleList.add(datiM);
							
							Answer answer = new Answer();
							answer.setAnswerIntegral("");
							answer.setAnswerMiddleId(datiMId);
							answer.setAnswerUpPhone("");
							answer.setAnswerUpTime(Constant.decodeDate());
							answer.setReceiveId(0);
							answerLst.add(answer);
						}else{
							Xulie xilie = new Xulie();
							String seriseId = Constant.getNum();
							xilie.setAnswerTypeId(Typeid);
							xilie.setCreateTime(Constant.decodeDate());
							xilie.setSeriseId(seriseId);
							xilie.setSeriseName(secondContent);
							xlList.add(xilie);
							xilieName.add(secondContent);
							hhtSerise.put(secondContent, seriseId);
							
							DatiMiddle  datiM = new DatiMiddle();
							String datiMId = Constant.getNumT();
							datiM.setAnswerContent(threeContent);
							datiM.setAnswerMiddleId(datiMId);
							datiM.setCreateTime(Constant.decodeDate());
							datiM.setRightAnswer(fourContent);
							datiM.setSeriseId(seriseId);
							datiMiddleList.add(datiM);
							
							Answer answer = new Answer();
							answer.setAnswerIntegral("");
							answer.setAnswerMiddleId(datiMId);
							answer.setAnswerUpPhone("");
							answer.setAnswerUpTime(Constant.decodeDate());
							answer.setReceiveId(0);
							answerLst.add(answer);
						}
					}else{
						DatiType datiTy= new DatiType();
						String dtTypeId=Constant.getNum();
						System.out.println("类型ID"+dtTypeId+"&&&"+firstContent);
						hhtType.put(firstContent, dtTypeId);
						//System.out.println("IDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDd="+hhtType.get(firstContent));
						datiTy.setAnswerTypeId(dtTypeId);
						datiTy.setCreateTime(Constant.decodeDate());
						datiTy.setTypeName(firstContent);
						datiTy.setUserId(user.getUserId());
						dtTypeLst.add(datiTy);
						saveTypeName.add(firstContent);
						
						Xulie xilie = new Xulie();
						String seriseId = Constant.getNum();
						xilie.setAnswerTypeId(dtTypeId);
						xilie.setCreateTime(Constant.decodeDate());
						xilie.setSeriseId(seriseId);
						xilie.setSeriseName(secondContent);
						xlList.add(xilie);
						xilieName.add(secondContent);
						hhtSerise.put(secondContent, seriseId);
						
						DatiMiddle  datiM = new DatiMiddle();
						String datiMId = Constant.getNumT();
						datiM.setAnswerContent(threeContent);
						datiM.setAnswerMiddleId(datiMId);
						datiM.setCreateTime(Constant.decodeDate());
						datiM.setRightAnswer(fourContent);
						datiM.setSeriseId(seriseId);
						datiMiddleList.add(datiM);
						
						Answer answer = new Answer();
						answer.setAnswerIntegral("");
						answer.setAnswerMiddleId(datiMId);
						answer.setAnswerUpPhone("");
						answer.setAnswerUpTime(Constant.decodeDate());
						answer.setReceiveId(0);
						answerLst.add(answer);
						
					}
				}
				for(Xulie xxx:xlList){
					System.out.println("名称"+xxx.getSeriseName());
				}
				if(dtTypeLst.size()>0){
					boolean datiTypeBo = new DatiTypeDao().saveDatiType(dtTypeLst);
					if(datiTypeBo){
						boolean xilieBo = new DatiTypeDao().saveXilie(xlList);
						if(xilieBo){
							boolean middleBo = new DatiDao().saveMiddle(datiMiddleList);
							if(middleBo){
								boolean answerBo = new DatiDao().saveAnswer(answerLst);
							}else{
								 request.getSession().setAttribute("result", "答题导入失败!");
							}
						}else{
							 request.getSession().setAttribute("result", "由于系列导入失败,导致答题导入失败!");
						}
					}else{
						 request.getSession().setAttribute("result", "由于类型导入失败,导致答题导入失败!");
					}
				}else{
						boolean xilieBo = new DatiTypeDao().saveXilie(xlList);
						if(xilieBo){
							boolean middleBo = new DatiDao().saveMiddle(datiMiddleList);
							if(middleBo){
								boolean answerBo = new DatiDao().saveAnswer(answerLst);
							}else{
								 request.getSession().setAttribute("result", "答题导入失败!");
							}
						}else{
							 request.getSession().setAttribute("result", "由于系列导入失败,导致答题导入失败!");
						}
				}
				
			}catch(Exception e){
				
			}
			
			
			 List<Object> list = this.getLst("", "",user.getUserId());
			 List<DatiType> datiTypeList =(List<DatiType>)list.get(0);
			 List<Answer> datiList = (List<Answer>)list.get(1);
			 
			 request.getSession().setAttribute("datiList", datiList);
			 request.getSession().setAttribute("datiTypeList", datiTypeList);
			
			 request.getSession().setAttribute("datiSelected", "0");
			 request.getSession().setAttribute("content","");
			 response.sendRedirect("hudong/datiList.jsp");
		}else if("setTime".equals(method)){//设置答题时间
			setTime setTime = new DatiDao().getSetTime1();
			request.getSession().setAttribute("setTime", setTime);
			request.getSession().setAttribute("result", "");
			response.sendRedirect("hudong/setTime.jsp");
		}else if("setTimeSubmit".equals(method)){
			String minutes = request.getParameter("minutes");
			setTime setT = new setTime();
			setT.setSetTime(minutes);
			setT.setId(1);
			boolean bo = new DatiDao().setTim(setT);
			if(bo){
				request.getSession().setAttribute("result", "时间设置成功");
			}else{
				request.getSession().setAttribute("result", "时间设置失败");
			}
			setTime setTime = new DatiDao().getSetTime1();
			request.getSession().setAttribute("setTime", setTime);
			response.sendRedirect("hudong/setTime.jsp");
		}
	}
	public List getLst(String datiType,String content,int userId){
		String condition="";
		if(datiType.equals("")&&content.equals("")){
			
		}else if(datiType.equals("")&&!content.equals("")){
			String middleCondition="answerContent like '%"+content+"%'";
			List<DatiMiddle> datiMiddleList = new DatiDao().getDatiMiddle("tb_answer_middle","createTime",middleCondition);
			String datiMiddleId = "";
			if(datiMiddleList!=null&&datiMiddleList.size()>0){
				for(DatiMiddle datiMiddle:datiMiddleList){
					if(datiMiddleId.equals("")){
						datiMiddleId+=datiMiddle.getAnswerMiddleId();
					}else{
						datiMiddleId+=","+datiMiddle.getAnswerMiddleId();
					}
				}
			}
			if(!datiMiddleId.equals("")){
				condition="answerMiddleId in("+datiMiddleId+")";
			}
		}else if(!datiType.equals("")&&content.equals("")){
			String xilieCondition="answerTypeId='"+datiType+"'";
			List<Xulie> xilieList = new DatiTypeDao().getXulieByTypeId("tb_serise", "", xilieCondition);
			String middleCondition="";
			String xilieId = "";
			String middleId="";
			if(xilieList!=null&&xilieList.size()>0){
				for(Xulie xilie:xilieList){
					if(xilieId.equals("")){
						xilieId+=xilie.getSeriseId();
					}else{
						xilieId+=","+xilie.getSeriseId();
					}
				}
				if(!xilieId.equals("")){
					middleCondition="seriseId in("+xilieId+")";
					List<DatiMiddle> datiMiddleList = new DatiDao().getDatiMiddle("tb_answer_middle","",middleCondition);
					if(datiMiddleList!=null&&datiMiddleList.size()>0){
						for(DatiMiddle datiMid:datiMiddleList){
							if(middleId.equals("")){
								middleId+=datiMid.getAnswerMiddleId();
							}else{
								middleId+=","+datiMid.getAnswerMiddleId();
							}
						}
					}
					if(!middleId.equals("")){
						condition="answerMiddleId in("+middleId+")";
					}
				}
			}
		}else if(!datiType.equals("")&&!content.equals("")){
			String xilieCondition="answerTypeId='"+datiType+"'";
			List<Xulie> xilieList = new DatiTypeDao().getXulieByTypeId("tb_serise", "", xilieCondition);
			String middleCondition="";
			String xilieId = "";
			String middleId="";
			if(xilieList!=null&&xilieList.size()>0){
				for(Xulie xilie:xilieList){
					if(xilieId.equals("")){
						xilieId+=xilie.getSeriseId();
					}else{
						xilieId+=","+xilie.getSeriseId();
					}
				}
				if(!xilieId.equals("")){
					middleCondition="seriseId in("+xilieId+") and answerContent like '%"+content+"%'";
					List<DatiMiddle> datiMiddleList = new DatiDao().getDatiMiddle("tb_answer_middle","",middleCondition);
					if(datiMiddleList!=null&&datiMiddleList.size()>0){
						for(DatiMiddle datiMid:datiMiddleList){
							if(middleId.equals("")){
								middleId+=datiMid.getAnswerMiddleId();
							}else{
								middleId+=","+datiMid.getAnswerMiddleId();
							}
						}
					}
					if(!middleId.equals("")){
						condition="answerMiddleId in("+middleId+")";
					}
				}
			}
		}
		
		String datiTypeCondition="userId="+userId;
		List<DatiType> datiTypeList = new DatiTypeDao().getAllDaTiType("tb_answer_type", "", datiTypeCondition);
		
		 List<Answer> datiList = new DatiDao().getAnswerList("tb_answer", "answerUpTime", condition);
		 List<Object> list = new ArrayList<Object>();
		 list.add(datiTypeList);
		 list.add(datiList);
		return list;
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		doGet(request,response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

	/**
	 *@author qingyu zhang
	 *@function:
	 *2011-4-4
	 *下午02:40:00
	 *zzClub
	 *com.dati.servlet
	 */
}
